﻿-- Define the relationship between ModelRoleAccess and SecurityRole
ALTER TABLE [dbo].[ModelRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_ModelRoleAccess_SecurityRole] FOREIGN KEY([SecurityRole])
REFERENCES [dbo].[SecurityRole] ([RoleId])
ON DELETE NO ACTION
GO
-- Define the relationship between ModelRoleAccess and Model
ALTER TABLE [dbo].[ModelRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_ModelRoleAccess_Model] FOREIGN KEY([Model])
REFERENCES [dbo].[Model] ([ModelId])
ON DELETE NO ACTION
GO
-- Define the relationship between ModelRoleAccess and Person
ALTER TABLE [dbo].[ModelRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_ModelRoleAccess_CreatedByPerson] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO
-- Define the relationship between ModelRoleAccess and Person
ALTER TABLE [dbo].[ModelRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_ModelRoleAccess_LastChangedBy] FOREIGN KEY([LastChangedBy])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO
-- Define the relationship between ModelRoleAccess and Person
ALTER TABLE [dbo].[ModelRoleAccess] WITH CHECK ADD  
       CONSTRAINT [FK_ModelRoleAccess_Person] FOREIGN KEY([Person])
REFERENCES [dbo].[Person] ([PersonId])
ON DELETE NO ACTION
GO